/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package demo_login;

import dao.Student;
import dao.StudentDao;
import dao.StudentDaoJDBCImpl;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author C079
 */
public class NewJFrame_add extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame_add
     */
    public NewJFrame_add() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextField_addName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField_addSex = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField_addAge = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField_addJava = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField_addMath = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextField_addSport = new javax.swing.JTextField();
        jButton_addSave = new javax.swing.JButton();
        jButton_addCancle = new javax.swing.JButton();

        jLabel1.setText("姓名");

        jTextField_addName.setText(" ");
        jTextField_addName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_addNameActionPerformed(evt);
            }
        });

        jLabel2.setText("性别");

        jTextField_addSex.setText(" ");

        jLabel3.setText("年龄");

        jTextField_addAge.setText(" ");

        jLabel4.setText("Java");

        jTextField_addJava.setText(" ");
        jTextField_addJava.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_addJavaActionPerformed(evt);
            }
        });

        jLabel5.setText("数学");

        jTextField_addMath.setText(" ");

        jLabel6.setText("体育");

        jTextField_addSport.setText(" ");
        jTextField_addSport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_addSportActionPerformed(evt);
            }
        });

        jButton_addSave.setText("保存");
        jButton_addSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_addSaveActionPerformed(evt);
            }
        });

        jButton_addCancle.setText("取消");
        jButton_addCancle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_addCancleActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField_addAge, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField_addMath, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField_addName, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextField_addJava, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField_addSex, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField_addSport, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton_addSave)
                        .addGap(39, 39, 39)
                        .addComponent(jButton_addCancle)))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField_addName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField_addSex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField_addAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField_addJava, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextField_addMath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextField_addSport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_addSave)
                    .addComponent(jButton_addCancle))
                .addGap(22, 22, 22))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField_addNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_addNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_addNameActionPerformed

    private void jButton_addCancleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_addCancleActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_jButton_addCancleActionPerformed

    private void jButton_addSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_addSaveActionPerformed
        // TODO add your handling code here:
        System.out.println("插入学生信息");
        Student s=new Student();
        s.setName(this.jTextField_addName.getText().trim());
        s.setGender(this.jTextField_addSex.getText().trim());
        s.setBirthday(new Date());
        s.getScoreList().get(0).setScore(Double.parseDouble(this.jTextField_addMath.getText()));
        s.getScoreList().get(1).setScore(Double.parseDouble(this.jTextField_addJava.getText()));
        s.getScoreList().get(2).setScore(Double.parseDouble(this.jTextField_addSport.getText()));
        System.out.println(s);
        StudentDao studentDao=new StudentDaoJDBCImpl();
        if(studentDao.writeStudent(s)){
            System.out.println("插入成功");
            JOptionPane.showMessageDialog(null, "学生信息插入成功","提示",JOptionPane.INFORMATION_MESSAGE); 
        }else{
            System.out.println("插入失败");
            JOptionPane.showMessageDialog(null, "插入失败，请检查","错误",JOptionPane.ERROR_MESSAGE); 
        }
    }//GEN-LAST:event_jButton_addSaveActionPerformed

    private void jTextField_addJavaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_addJavaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_addJavaActionPerformed

    private void jTextField_addSportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_addSportActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_addSportActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame_add.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame_add.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame_add.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame_add.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
            	NewJFrame_add add= new NewJFrame_add();
            	add.setVisible(true);
            	add.setTitle("添加学生信息界面");
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_addCancle;
    private javax.swing.JButton jButton_addSave;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField jTextField_addAge;
    private javax.swing.JTextField jTextField_addJava;
    private javax.swing.JTextField jTextField_addMath;
    private javax.swing.JTextField jTextField_addName;
    private javax.swing.JTextField jTextField_addSex;
    private javax.swing.JTextField jTextField_addSport;
    // End of variables declaration//GEN-END:variables
}
